<template>
  <!-- 面包屑 -->
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="6">
          <div>
            <el-input v-model="queryParam.username" placeholder="请输入内容" class="input-with-select" @clear="getUserList"
              clearable>
              <el-button @click="getUserList" slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </div>
        </el-col>
  <!--     <el-col :span="6">
          <el-button type="primary" @click="addWorkerFormVisible = true">添加工人</el-button>
        </el-col> -->
      </el-row>
      <template>
        <el-table :data="userListData" style="width: 100%" max-height="250" stripe>
          <el-table-column fixed type="index"></el-table-column>
          <el-table-column fixed prop="username" label="账号" width="150">
          </el-table-column>
          <el-table-column prop="nickname" label="昵称" width="120">
          </el-table-column>
          <el-table-column prop="gender" label="性别" width="120">
          </el-table-column>
          <el-table-column prop="province" label="省份" width="120">
          </el-table-column>
          <el-table-column prop="city" label="城市" width="120">
          </el-table-column>
          <el-table-column prop="is_active" label="状态" width="120">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="150">
            <!--  slot-scope="scope" -->
            <template>
              <el-tooltip class="item" effect="dark" content="查看" placement="top" :enterable="false">
                <el-button size="mini" type="warning" icon="el-icon-view" circle></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryParam.currentPage"
        :page-sizes="[10, 20, 30, 40]" :page-size="queryParam.pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total="totalResult">
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        userListData: [],
        totalResult: 0,
        queryParam: {
          username: '',
          currentPage: 1,
          pageSize: 10
        }
      }
    },
    created() {
      this.getUserList()
    },
    methods: {
      async getUserList() {
        // 获取会员信息
        const {
          data: res
        } = await this.$http.get('account/member/', {
          params: this.queryParam
        })
        console.log(res)
        this.userListData = res.data.dataList
        this.totalResult = res.data.totalResult
      },
      // 分页事件
      handleSizeChange(newSize) {
        this.queryParam.pageSize = newSize
        this.queryParam.currentPage = 1
        this.getUserList()
      },
      handleCurrentChange(newPage) {
        this.queryParam.currentPage = newPage
        this.getUserList()
      }
    }
  }
</script>
<style>
  .el-pagination {
    text-align: center;
    margin-top: 15px;
  }
</style>
